package com.skytech.component.crawler.parse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.skytech.component.crawler.scratch.PageContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



@Service
public class SaveDataToES implements ISaveData {
    @Autowired
    private RestTemplateBuilder restTemplateBuilder;
    @Value("${elasticsearch.server}")
    private String server;



    @Transactional
    @Override
    public void saveData(JSONObject jsonObject) {
        //JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(pageContent));
       // jsonObject.remove("id");
       // restTemplateBuilder.build().put(server + "crawler_news/news/" + jsonObject.get("id"), jsonObject);
        //restTemplateBuilder.build().put(server + "bid/bid/" + jsonObject.get("id"), jsonObject);
        restTemplateBuilder.build().put(server + jsonObject.getString("dataType")+"/news/"+ jsonObject.get("id"), jsonObject);
    }




/*
    private void createIndex(){
        client.indices().create("",).get();
        restTemplateBuilder.build().
    }*/


}
